﻿/****************************************************************************
*  Arthea Server by R. Jennings (2007-2008)   http://arthea.googlecode.com/ *
*  By using this code you comply with the Artistic and GPLv2 Licenses.      *
****************************************************************************/
using System.Collections.Generic;

namespace Arthea.Collections
{
    /// <summary>
    /// Implementation of <see cref="ExtraDescription"/>
    /// </summary>
    public class ExtraDescription
    {

		#region Fields (1) 


        private Dictionary<string, string> extra = new Dictionary<string, string>();

		#endregion Fields 

		#region Read only Properties (1) 

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <value>The count.</value>
        public int Count
        {
            get { return extra.Count; }
        }

		#endregion Read only Properties 

		#region Properties (1) 


        /// <summary>
        /// Gets or sets the <see cref="System.String"/> with the specified keyword.
        /// </summary>
        /// <value></value>
        public string this[string keyword]
        {
            get 
            {
                if (extra.ContainsKey(keyword))
                    return extra[keyword];
                else
                    return null;
            }
            set 
            {
                if (extra.ContainsKey(keyword))
                    extra[keyword] = value;
                else
                    extra.Add(keyword, value);
            }
        }


		#endregion Properties 

		#region Public Methods (2) 

        /// <summary>
        /// Determines whether [contains] [the specified keyword].
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified keyword]; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(string keyword)
        {
            return extra.ContainsKey(keyword);
        }

        /// <summary>
        /// Finds the description.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <param name="count">The count.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public string FindDescription(string keyword, ref int count, int index)
        {
            foreach (KeyValuePair<string, string> entry in extra)
            {
                if (keyword == entry.Key && ++count == index)
                {
                    return entry.Value;
                }
            }
            return null;
        }

        /// <summary>
        /// Adds the specified keyword.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <param name="description">The description.</param>
        public void Add(string keyword, string description)
        {
            extra.Add(keyword, description);
        }

        /// <summary>
        /// Removes the specified keyword.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <returns></returns>
        public bool Remove(string keyword)
        {
            return extra.Remove(keyword);
        }

		#endregion Public Methods 

    }
}
